package com.scf.preloanmanage.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scf.entity.EnterpriseIfmtion;
import com.scf.entity.PageBean;
import com.scf.preloanmanage.entity.PreLoan;
import com.scf.preloanmanage.service.PreLoanService;
import com.scf.service.EnterpriseService;
import com.scf.service.HistoryService;
import com.scf.uitl.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-15-10:45
 */
@RestController
@RequestMapping("/preloan")
public class PreLoanController {
    @Resource
    PreLoanService preLoanService;

    @Resource
    HistoryService historyService;

    @Resource
    EnterpriseService enterpriseService;

    @GetMapping("/select")
    public ResponseResult<PageInfo<PreLoan>> select(PreLoan preLoan,Integer pageIndex,Integer pageSize) {

        PageHelper.startPage(pageIndex, pageSize);
        ResponseResult<PageInfo<PreLoan>> responseResult = new ResponseResult<>();
        try {
            List<PreLoan> getPreLoan = preLoanService.getPreLoan(preLoan);
            PageInfo<PreLoan> pageInfo = new PageInfo<>(getPreLoan);
            System.out.println(pageInfo);
            responseResult.setData(pageInfo);
            responseResult.setCode(200);
            responseResult.setMessage("贷前管理查询成功");
            return responseResult;
        } catch (Exception e) {
            System.out.println(e);
            responseResult.setData(null);
            responseResult.setCode(500);
            responseResult.setMessage("系统异常");
            return responseResult;
        }
    }

    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody PreLoan preLoan){
        System.out.println(preLoan);
        boolean update = preLoanService.update(preLoan);

        if(update){
            ResponseResult responseResult=new ResponseResult();
            responseResult.setData(null);
            responseResult.setCode(200);
            responseResult.setMessage("新增成功");
            return responseResult;
        }
        return null;
    }

    @GetMapping("/getInfo")
    public ResponseResult getInfo(@RequestParam String plname){


        ResponseResult<PageBean<EnterpriseIfmtion>> all = enterpriseService.getAll(plname, 1, 1, 5);
        System.out.println(all);
        return all;
    }

    @GetMapping("/history/{plid}")
    public ResponseResult history(@PathVariable("plid") int plid){

        ResponseResult select = historyService.select(plid);
        return select;
    }


}
